package org.skyui.views;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;

import org.skyui.beans.AbstractBean;

import com.vaadin.terminal.StreamResource.StreamSource;

public class ByteArrayStreamSource implements StreamSource {

	ByteArrayInputStream bis = null;

	ByteArrayStreamSource(AbstractBean bean, String getMethod) {
		Method method;
		try {
			method = bean.getClass().getMethod(getMethod);
			byte[] data = (byte[]) method.invoke(bean);
			if (data != null)
				bis = new ByteArrayInputStream(data);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public InputStream getStream() {
		return bis;
	}

}
